import "dotenv/config.js";

import { Command } from "commander";
import db from "../src/database.js";

import { makePassword } from "../src/utils.js";

const program = new Command();
program
  .name("AddUser")
  .description("cli to add user password and email")
  .version("0.0.1");
program
  .requiredOption("-e, --email <email>", "email")
  .requiredOption("-p, --password <password>", "password")
  .parse(process.argv);

const options = program.opts();

(async () => {
  const { email, password } = options;
  const passwordHash = makePassword(password);
  await db.insert`INSERT INTO User (email, password, nickname, active)
	values (${email}, ${passwordHash}, ${email}, 1)`;
  await db.close();
})();
